The present invention relates generally to data processing systems and, more particularly, to an object-relational mapping tool for accessing data stored in relational database tables that do not utilize primary keys.
Object-relational mapping tools have been created to facilitate development of application programs that utilize a relational database. A relational database stores data in tables having rows (records) and columns (fields). The tables are usually interrelated, and thus, there is a logical structure imposed on the database. This logical structure is known as a schema. Each table may have a primary key, comprising one or more columns that uniquely identify a row. For example, in a table with rows of customers, a column storing each customer""s social security number may be used as the primary key because it uniquely identifies each customer in the table. However, one may have relational database tables that do not have primary keys.
Object-relational mapping tools read database schema information and automatically generate source code from the database. This source code contains a number of classes whose interrelationships reflect the logical structure, or schema, of the database. A class, such as a Java(trademark) class, is a data structure containing both data members that store data and function members (or methods) that act upon the data. The source code may contain one class for each table in the database, and each class may have a data member for each column in the corresponding table. Additionally, the classes contain function members that are used to both get and set the values for the data members and, eventually, update the database.
By using an object-relational mapping tool, a programmer can automatically generate source code to facilitate database application development. After the source code is generated, the programmer writes code to interact with only the classes in the source code and not the database, thus hiding the complexities of interacting with the database from the programmer. This allows a programmer who is familiar with object-oriented programming to code against familiar classes and not unfamiliar, sometimes cumbersome to use, database query languages.
When a database schema is mapped to classes, most tables map directly to classes. Each row within a table maps to an instance of the class, and is identified with a unique object identifierxe2x80x94the primary key for tables with primary keys. The object-relational mapping tool relies on the unique object identifiers corresponding to the primary keys to maintain information in the corresponding relational database table. For example, conventional object-relational mapping tools use the unique object identifiers to update and delete information contained in the corresponding relational database table. The conventional object-relational mapping tools, however, cannot maintain information in relational database tables without primary keys. Thus, there is a need for systems and methods that permit object-relational mapping tools to maintain database tables without primary keys.
In accordance with methods and systems consistent with the present invention, an object-relational mapping tool is provided that can be used to maintain information in relational database tables that do not use primary keys. The object-relational mapping tool uses a cursor update operation associated with relational database tables to maintain information contained in the relational database table, including performing operations such as, updating rows, and deleting rows from the table.
In accordance with methods consistent with the present invention, a method is provided in a computer system having a non-primary key table. The method, upon receiving a selection instruction with a set of values, identifies all columns from the table with all of the specified values to select a set of rows from the table, and then for each selected row the method creates an object with a unique identifier and populates attributes of the object with values from all of the columns that form the selected row.
In accordance with methods consistent with the present invention, another method is provided in a computer system having a non-primary key table, where each row in the table is being represented by a corresponding object. The method, upon receiving an update instruction to update values of attributes of an object, selects rows with all of the same values as stored in the object using cursor update, and updates one of the selected row with values from the instruction.
In accordance with methods consistent with the present invention, yet another method is provided in a computer system having a non-primary key table, where each row in the table is being represented by a corresponding object. The method, upon receiving a delete instruction to delete an object, selects rows with all of the same values as stored in the object using cursor update, and deletes one of the selected rows.
In accordance with systems consistent with the present invention, a data processing system is provided comprising a secondary storage device, a memory, and a processor. The memory contains a non-primary key table with rows and columns and an object-relational mapping tool configured to, upon receiving a selection instruction with a set of values, identify all columns with all of the values specified in the set to select a set of rows from the table, and for each selected row, create an object with a unique identifier and populate attributes of the object with values from the columns that form the selected row. The processor is configured to run the object-relational mapping tool.
In accordance with systems consistent with the present invention, a data processing system is provided comprising a secondary storage device, a memory, and a processor. The memory contains a non-primary key table with rows and columns, and an object-relational mapping tool configured to, upon receiving an update instruction, select a row with all of the same values as stored in the object using cursor update, and update one of the selected row with values from the instruction. The processor is configured to run the object-relational mapping tool.
In accordance with systems consistent with the present invention, a data processing system is provided comprising a secondary storage device, a memory, and a processor. The memory contains a non-primary key table with rows and columns and an object-relational mapping tool configured to, upon receiving a delete instruction, select rows with all of the same values as stored in the object using cursor update, and delete one of the selected rows. The processor is configured to run the object-relational mapping tool.